package com.yuncheng.oaApi.FlowController;


import com.yuncheng.entity.YcSysUser;
import com.yuncheng.oaApi.constant.OaCommonFlowConstant;
import com.yuncheng.oaApi.constant.OaLogConstant;
import com.yuncheng.oaApi.constant.OaFlowConstant;
import com.yuncheng.oaApi.vo.OaFlowVo;
import com.yuncheng.oaApi.vo.OaLgqsVo;
import com.yuncheng.oaApi.vo.OaReturnVo;
import com.yuncheng.oaApi.vo.Result;
import com.yuncheng.spcyApi.service.ISpcyLogService;
import org.apache.commons.collections.CollectionUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuncheng.oaApi.FlowService.NewOalgqsFlowService;
import com.yuncheng.annotation.AutoLog;
import com.yuncheng.oaApi.busService.OaFlowNodeDbrService;
import com.yuncheng.oaApi.busService.MyLcFlowService;
import com.yuncheng.oaApi.entity.*;
import com.yuncheng.oaApi.mapper.OaLgqsFlowMapper;
import com.yuncheng.oaApi.service.*;
import com.yuncheng.spcyApi.utils.DateConvert;
import com.yuncheng.oaApi.utils.GetUuIdUtils;
import com.yuncheng.utils.ThreadContextHelper;
import com.yuncheng.vo.*;
import groovy.lang.Lazy;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;
import utils.DateConversionUtils;
import utils.LogUtils;
import utils.ObjectToMapUtils;

import javax.annotation.Resource;
import java.lang.reflect.InvocationTargetException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;

@Api(tags = "NEW_OA-离岗请示登记管理接口")
@RestController
@RequestMapping("/api/spzx-oa/newflow-lgqs")
public class NewOaLgqsFlowController {
    private static final Logger log = LoggerFactory.getLogger(NewOaLgqsFlowController.class);


    @Resource
    private OaLgqsFlowMapper oaLgqsFlowMapper;

    @Resource
    private NewOalgqsFlowService newOalgqsFlowService;

    @Resource
    private IOaLgqsService oaLgqsService;

    @Resource
    private IOaSpcySqsxJobService spcySqsxJobService;

    @Resource
    private IOaYcSysUserService ycSysUserService;

    @Resource
    @Lazy
    private IOaSysTzMessageService sysTzMessageService;

    @Resource
    @Lazy
    private OaFlowNodeDbrService oaFlowNodeDbrService;
    @Resource
    @Lazy
    private MyLcFlowService myLcFlowService;

    @Resource
    @Lazy
    private IOaSysFlowNodeService sysFlowNodeService;

    @Resource
    @Lazy
    private IOaSysFlowTempleService sysFlowTempleService;

    @Resource
    @Lazy
    private ISpcyLogService spcyLogService;

    @Resource
    @Lazy
    private IOaProcessBusinessService oaProcessBusinessService;


    /**
     * 流程列表分页查询
     * @param oaLgqsVo
     * @param pageNo
     * @param pageSize
     * @param onlyCurrentUser
     * @return
     */
    @AutoLog(value = "流程监控-分页查询")
    @ApiOperation(value = "流程监控-分页查询")
    @GetMapping("flowJkPage")
    public HttpResult flowJkPage(
            OaLgqsVo oaLgqsVo,
            @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
            @RequestParam(name = "onlyCurrentUser", defaultValue = "false") boolean onlyCurrentUser) {
        CurrentUserVo user = ThreadContextHelper.getCurrentUser();
        if (user == null) {
            return HttpResult.error("请重新登录，Token已失效！");
        }
        oaLgqsVo.setFlcmc(OaFlowConstant.OA_LGQS_NAME);
        Page<OaLgqsVo> page = new Page<>(pageNo, pageSize);

        IPage<OaLgqsVo> list = null;
        if (StringUtils.isNotBlank(oaLgqsVo.getOaid())){
            OaLgqs xcxxspgl = oaLgqsService.getById(oaLgqsVo.getOaid());
            if (xcxxspgl != null){
                list = oaLgqsFlowMapper.flowJkPage(page,onlyCurrentUser,user,oaLgqsVo);
            }
        }



        return HttpResult.ok(list);
    }

    /**
     * 流程列表分页查询
     * @param oaLgqsVo
     * @param pageNo
     * @param pageSize
     * @param onlyCurrentUser
     * @return
     */
    @AutoLog(value = "流程列表-分页查询")
    @ApiOperation(value = "流程列表-分页查询")
    @GetMapping("flowJobPage")
    public HttpResult<?> flowJobPage(
            OaLgqsVo oaLgqsVo,
            @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
            @RequestParam(name = "onlyCurrentUser", defaultValue = "true") boolean onlyCurrentUser) {
        CurrentUserVo user = ThreadContextHelper.getCurrentUser();
        if (user == null) {
            return HttpResult.error("请重新登录，Token已失效！");
        }
        oaLgqsVo.setFlcmc(OaFlowConstant.OA_LGQS_NAME);
        if (StringUtils.isBlank(oaLgqsVo.getFblzt())) {
            oaLgqsVo.setFblzt(OaCommonFlowConstant.BLZT_DB);
        }
        Page<OaLgqsVo> page = new Page<>(pageNo, pageSize);
        IPage<OaLgqsVo> list = oaLgqsFlowMapper.flowJobPage(page, onlyCurrentUser, user, oaLgqsVo);
        return HttpResult.ok(list);
    }


    /**
     * 我的已办
     */
    @AutoLog(value = "流程列表-我的已办")
    @ApiOperation(value = "流程列表-我的已办")
    @GetMapping("myJobPage")
    public HttpResult<?> myJobPage(
            @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
            OaLgqsVo oaLgqsVo) {
        CurrentUserVo user = ThreadContextHelper.getCurrentUser();
        if (user == null) {
            return HttpResult.error("请重新登录，Token已失效！");
        }
        Page<OaLgqsVo> page = new Page<>(pageNo, pageSize);
        IPage<OaLgqsVo> list = oaLgqsFlowMapper.myYbFlowPage(page, true, user, oaLgqsVo);
        return HttpResult.ok(list);
    }


    /**
     * 数据修订
     */
    @AutoLog(value = "列表-数据修订")
    @ApiOperation(value = "列表-数据修订")
    @GetMapping("Pagesjxd")
    public HttpResult<?> Pagesjxd(
            @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
            OaLgqsVo oaLgqsVo) {

        CurrentUserVo user = ThreadContextHelper.getCurrentUser();
        if (user == null) {
            return HttpResult.error("请重新登录，Token已失效！");
        }

        Page<OaLgqsVo> page = new Page<>(pageNo, pageSize);
        IPage<OaLgqsVo> list = oaLgqsFlowMapper.myYbFlowPage(page, false, user, oaLgqsVo);
        return HttpResult.ok(list);
    }



    @AutoLog(value = "发起离岗流程")
    @ApiOperation(value = "发起离岗流程")
    @PostMapping(value = "initBzFlow")
    public HttpResult<?> initBzFlow(@RequestBody OaLgqs oaLgqs) {

        String oaid = "";
        //当前人的id
        CurrentUserVo currentUser = ThreadContextHelper.getCurrentUser();
        if (currentUser == null) {
            return HttpResult.error("当前登录已失效，请重新登录");
        }
        if (StringUtils.isNotBlank(oaLgqs.getId())){
            OaLgqs oaids = oaLgqsService.getById(oaLgqs.getId());

            ConvertUtils.register(new DateConvert(), Date.class);
            try {
                BeanUtils.populate(oaids, BeanUtils.describe(oaLgqs));
            } catch (IllegalAccessException e) {
                log.error("出错-保存事项【非法访问异常】,{}", e.getMessage());
            } catch (InvocationTargetException e) {
                log.error("出错-保存事项【调用TargetException】,{}", e.getMessage());
            } catch (NoSuchMethodException e) {
                log.error("出错-找不到可用方法", e.getMessage());
            }
            oaid = oaLgqs.getId();

            // Date日期单独做处理
            oaids.setFlgsj(oaLgqs.getFlgsj());
            oaids.setFhgsj(oaLgqs.getFhgsj());
            oaids.setFuserid(currentUser.getId());


            oaLgqsService.updateById(oaids);
        }else {
            oaid = GetUuIdUtils.ReplaceUuId();
            String timeStr = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));

            oaLgqs.setId(oaid);
            oaLgqs.setFxm(currentUser.getName());
            oaLgqs.setFuserid(currentUser.getId());
            oaLgqs.setFbssj(timeStr);
            oaLgqs.setFtbbm(currentUser.getDeptName());
            YcSysUser ycSysUserById = ycSysUserService.getYcSysUserById(currentUser.getId());
            oaLgqs.setFzw(ycSysUserById.getFzw());
            oaLgqs.setFlczt(OaCommonFlowConstant.FLOW_LCZB);
            oaLgqs.setFbz("1.因公离岗在南宁市范围内参加外单位（部门）委派工作的，须附相关证明材料。离岗1日以内（含1日）须由本科室负责人签署意见，报分管领导审批，1日以上须加报中心主任审批；\n" +
                    "2.因私离岗2小时以内（含2小时）须经本科室负责人审核，并报分管领导批准；3.请假结束需本人按时到办公室销假；\n" +
                    "4.登记表统一交中心办公室保存。");

            oaLgqsService.save(oaLgqs);
        }

        /**
         * @Author: lhb
         * @Description : 是否发起流程   如果是开始申请就跳转流程
         *               在这里设置 nextNodeName 指定下个环节节点 做当前跳转流程的判断，然后设置变量接收环节的值，写到nextNodeName中
         * @DateTime:
         * @Params: Fsffqlc
         */
        String msg = "保存成功";
        String lcmbCode = OaFlowConstant.OA_LGQS;

        OaJobEntity job = new OaJobEntity();
        // 初始化流程
        Result result = newOalgqsFlowService.createProcess(lcmbCode,oaid, currentUser);
        //做一次规则校验 如果查到此oaid 在表中已经插入 那就执行更新
        OaLgqs lgqsServiceById = oaLgqsService.getById(oaid);
        List<OaProcessBusiness> oaProcessBusinessList = oaProcessBusinessService.list(new LambdaQueryWrapper<OaProcessBusiness>()
                                                                                            .eq(OaProcessBusiness::getFpid, oaid));
        String bt = currentUser.getName()+"提交的离岗请示"; //标题
        String zy = new String();
        if (lgqsServiceById.getFlgsj() != null && lgqsServiceById.getFhgsj() != null) {
             zy = "开始时间:[" + DateConversionUtils.DateToYMDHMSChineseString(lgqsServiceById.getFlgsj()) + "]" + "\n"
                    + "结束时间:[" + DateConversionUtils.DateToYMDHMSChineseString(lgqsServiceById.getFhgsj()) + "]" + "\n"
                    + "时长:" + lgqsServiceById.getFlksj() + "小时";
        }
        if (oaProcessBusinessList.size() == 0){
            //初始化的时候 像 流程业务主表添加拼接初始化数据
            oaProcessBusinessService.addProcess(oaid,zy,bt,lcmbCode,OaFlowConstant.OA);

        }else {
            String id = oaProcessBusinessList.get(0).getId();  //当前已经插入的主键id 然后更新 摘要信息
            OaProcessBusiness oaProcessBusiness = oaProcessBusinessService.getById(id);
            oaProcessBusiness.setFzy(zy);
            oaProcessBusinessService.updateById(oaProcessBusiness);

        }

        if (!result.isSuccess()){
            return HttpResult.error(result.getMessage());
        }else {
             job = (OaJobEntity)result.getResult();
            if (job != null) {
                // 是否提交流程
                if(StringUtils.isBlank(oaid)){
                    return HttpResult.error("参数丢失");
                }
                String nextNodeId = "";
                String nextNodeDbrId = "";
                if (StringUtils.isNotBlank(oaLgqs.getFsffqlc()) && oaLgqs.getFsffqlc().equals(OaCommonFlowConstant.SFFQLC_YES)) {
                    YcSysUser byId = ycSysUserService.getById(currentUser.getId());

                    if (StringUtils.isBlank(oaLgqs.getFtbbm())) {
                        return HttpResult.error("请完善个人信息部门名称栏");
                    }
//                    if (StringUtils.isBlank(byId.getFzc())) {
//                        return HttpResult.error("请完善个人信息职称栏");
//                    }

                    if (StringUtils.isBlank(oaLgqs.getFlczt())) {
                        oaLgqs.setFlczt(OaCommonFlowConstant.FLOW_LCZB);
                    }
                    //使用流程编码查询流程模板
                    List<OaSysFlowTemple> templeList = sysFlowTempleService.list(new LambdaQueryWrapper<OaSysFlowTemple>().eq(OaSysFlowTemple::getFlcbm, lcmbCode));
                    String templeId = templeList.get(0).getId();

                    List<OaSysFlowNode> flowNodeList = sysFlowNodeService.list(new LambdaQueryWrapper<OaSysFlowNode>().eq(OaSysFlowNode::getFlcmbid, templeId)
                                                                                                .eq(OaSysFlowNode::getFjdmc, OaFlowConstant.LGQS_HJMC_FGSP));

                    String nodeList = flowNodeList.get(0).getId();
                    //先判断是否为中心副主任 。在继续判断 是否是科室负责人
                    if (oaLgqs.getFtbbm().contains(OaCommonFlowConstant.ORG_NAME_ZXFZR)) {
                        //如果填报部门为中心副主任 则跳到 分管审批  且环节待办人为中心主任
                        nextNodeId = nodeList;
                        Map zxld = oaFlowNodeDbrService.getZxld();
                        String dbrId = zxld.get("dbrId").toString();
                        nextNodeDbrId = dbrId;

                    } else if (oaFlowNodeDbrService.brksfzr()) {
                        nextNodeId = nodeList;
                        nextNodeDbrId = "";
                    } else {
                        nextNodeId = "";
                        nextNodeDbrId = "";
                    }

                    Result result1 = newOalgqsFlowService.passJob(oaid,job.getId(),"同意", nextNodeId, nextNodeDbrId);
                    if (!result1.isSuccess()) {
                        return HttpResult.error(result.getMessage());
                    }
                    msg = "提交成功";
                    //提交完成后 更新通知信息
                    sysTzMessageService.tjMessage(oaid);

                    List<OaProcessBusiness> oaProcessBusinessList1 = oaProcessBusinessService.list(new LambdaQueryWrapper<OaProcessBusiness>()
                                                                            .eq(OaProcessBusiness::getFpid, oaid));
                    OaProcessBusiness oaProcessBusiness = oaProcessBusinessList1.get(0);
                    OaProcessBusiness byId1 = oaProcessBusinessService.getById(oaProcessBusiness.getId());
                    byId1.setFsfkch(0);
                    byId1.setFcshdb(OaFlowConstant.FLOW_BLZT_YB);
                    oaProcessBusinessService.updateById(byId1);

                    myLcFlowService.recall(oaid);
                }
            }
        }

        HashMap map = new HashMap();
        map.put("msg",msg);
        map.put("oaMap",oaLgqs);
        map.put("jobMap",job);

        return HttpResult.ok(map);
    }

    /**
     * 离岗流程保存接口
     */
    @AutoLog(value = "离岗流程保存接口")
    @ApiOperation(value = "离岗流程保存接口")
    @PostMapping(value = "/saveFlow")
    public HttpResult<?> saveFlow(@RequestBody OaFlowVo oaFlowVo) {
        String submitType = OaCommonFlowConstant.SUBMIT_TYPE_SAVE; // 保存

        String jobId = oaFlowVo.getJobid(); // 当前流程任务id
        String oaid = oaFlowVo.getOaid(); // 当前办公主键id
        String opinion = oaFlowVo.getOpinion(); // 办理意见

        if (StringUtils.isBlank(oaFlowVo.getLcmbCode())){
            oaFlowVo.setLcmbCode(OaFlowConstant.OA_LGQS);
        }
        if (StringUtils.isBlank(jobId)){
            return HttpResult.error("流程任务id参数丢失，请联系管理员");
        }
        // 流程处理
        Result httpResult = newOalgqsFlowService.handleFlow(oaFlowVo, null, jobId, oaid, submitType, opinion);
        if (!httpResult.isSuccess()){
            return HttpResult.error(httpResult.getMessage());
        }
        Map map = new HashMap();
        HttpResult<Object> res = new HttpResult<>(true);
        res.setMessage("保存成功");
        res.setResult(map);
        return res;
    }

//    /**
//     * 离岗流程提交接口
//     */
    @AutoLog(value = "离岗流程提交接口")
    @ApiOperation(value = "离岗流程提交接口")
    @PostMapping(value = "/submitFlow")
    public HttpResult<?> submitFlow(@RequestBody OaFlowVo oaFlowVo) {

        String submitType = OaCommonFlowConstant.SUBMIT_TYPE_SUBMIT; // 提交

        String jobId = oaFlowVo.getJobid();
        String oaid = oaFlowVo.getOaid();
        String opinion = oaFlowVo.getOpinion();
        OaLgqs oaId = oaLgqsService.getById(oaid);
        OaJobEntity jobid = spcySqsxJobService.getById(jobId);
        if (StringUtils.isBlank(oaFlowVo.getLcmbCode())){
            oaFlowVo.setLcmbCode(OaFlowConstant.OA_LGQS);
        }


        if (jobid.getFhjmc().equals(OaFlowConstant.LGQS_HJMC_XJ)) {

        } else {
            oaId.setFlczt(OaCommonFlowConstant.FLOW_LCZB);
        }
        if (StringUtils.isBlank(oaId.getFsffqlc())) {
            oaId.setFsffqlc(OaCommonFlowConstant.SFFQLC_YES);
        }

        oaLgqsService.updateById(oaId);

        if (StringUtils.isBlank(jobId)) {
            return HttpResult.error("流程任务id参数丢失，请联系管理员");
        }
        /* if (StringUtils.isBlank(opinion)){
            return HttpResult.error("请填写办理意见");
        }*/
        OaJobEntity nowJob = null;
        Result httpResult1 = newOalgqsFlowService.handleFlow(oaFlowVo, nowJob, jobId, oaid, submitType, opinion);
        if (!httpResult1.isSuccess()){
            return HttpResult.error(httpResult1.getMessage());
        }
        List<OaProcessBusiness> oaProcessBusinessList1 = oaProcessBusinessService.list(new LambdaQueryWrapper<OaProcessBusiness>()
                .eq(OaProcessBusiness::getFpid, oaid));
        OaProcessBusiness oaProcessBusiness = oaProcessBusinessList1.get(0);
        OaProcessBusiness byId1 = oaProcessBusinessService.getById(oaProcessBusiness.getId());
        byId1.setFsfkch(0);
        byId1.setFcshdb(OaFlowConstant.FLOW_BLZT_YB);
        oaProcessBusinessService.updateById(byId1);
        //提交完成后 更新待办信息
        sysTzMessageService.tjMessage(oaid);
        myLcFlowService.recall(oaid);

        return HttpResult.ok("提交成功");
    }


    // 批量销假
    @AutoLog(value = "批量已办销假环节-通过当前jobid 用逗号隔开")
    @ApiOperation(value = "批量已办销假环节-通过当前jobid 用逗号隔开")
    @ApiImplicitParam(value = "jobids", name = "jobids", required = true)
    @GetMapping(value = "allxj")
    public HttpResult<?> allxj(@RequestParam("jobids") String jobids){
        CurrentUserVo currentUser = ThreadContextHelper.getCurrentUser();
        List<String> xjList = Arrays.asList(jobids.split(","));
        for (String xjid:xjList){
            newOalgqsFlowService.doJobs(xjid, "同意");
        }
        for (String jobid:xjList){
            List<OaJobEntity> list = spcySqsxJobService.list(new LambdaQueryWrapper<OaJobEntity>().eq(OaJobEntity::getId, jobid));
            for (OaJobEntity lists: list){
                String fpid = lists.getFpid();
                if (StringUtils.isBlank(fpid)){
                    return HttpResult.error("获取不到oaid 请联系管理员");
                }
                OaLgqs oalgqs = oaLgqsService.getById(lists.getFpid());
                oalgqs.setFxjr(currentUser.getName());
                oalgqs.setFxjsj(DateConversionUtils.DateToDays(new Date()));
                oaLgqsService.updateById(oalgqs);
            }
        }
        return HttpResult.ok("更新成功");
    }


    /**
     * 批量查询
     */
    @AutoLog(value = "批量查询")
    @ApiOperation(value = "批量查询")
    @ApiImplicitParam(value = "jobids", name = "jobids", required = true)
    @GetMapping(value = "queryBatchJobByJobIds")
    public HttpResult<?> queryBatchJobByJobIds(@RequestParam("jobids")String jobids) {
        if (StringUtils.isBlank(jobids)) {
            return HttpResult.error("参数不能为空,请选择数据");
        }
        List<Map> mapList = new ArrayList<>();
        List<String> jobidsList = Arrays.asList(jobids.split(","));
        if (CollectionUtils.isNotEmpty(jobidsList)) {
            for (String jobid : jobidsList){
                mapList.add(newOalgqsFlowService.getJobConcernByJobId(jobid));
            }
        }
        return HttpResult.ok(mapList);
    }

    /**
     * 查询当前流程任务详情-通过当前流程任务id
     */
    @AutoLog(value = "查询当前流程任务详情-通过当前流程任务id")
    @ApiOperation(value = "查询当前流程任务详情-通过当前流程任务id")
    @ApiImplicitParam(value = "jobid", name = "流程任务id", required = true)
    @GetMapping(value = "queryJobByJobId")
    public HttpResult<?> queryJobByJobId(@RequestParam("jobid") String jobid) {
        if (StringUtils.isBlank(jobid)) {
            return HttpResult.error("流程任务id不能为空");
        }
        Map map = newOalgqsFlowService.getJobConcernByJobId(jobid);
        return HttpResult.ok(map);
    }

    /**
     * 获取已办列表-通过当前流程id-自定义退回
     *
     * @param jobid
     * @return
     */
    @AutoLog(value = "获取已办列表-通过当前流程id-自定义退回")
    @ApiOperation(value = "获取已办列表-通过当前流程id-自定义退回")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "jobid", value = "流程任务id"),
            @ApiImplicitParam(name = "isZdhj", value = "是否指定环节，默认：true，指定")
    })
    @GetMapping(value = "queryAllYbJob")
    public HttpResult<?> queryAllYbJob(@RequestParam(value = "jobid", defaultValue = "") String jobid,
                                       @RequestParam(value = "isZdhj", defaultValue = "true") boolean isZdhj) {
        List<Map<String, String>> currentJobPrevious = newOalgqsFlowService.getCurrentJobPrevious(jobid, isZdhj);
        return HttpResult.ok(currentJobPrevious);
    }

    /**
     * 退回环节
     *
     * @return
     */
    @AutoLog(value = "自定义-退回环节")
    @ApiOperation(value = "自定义-退回环节")
    @PostMapping(value = "returnUpperzdyFlowJob")
    public HttpResult<?> returnUpperzdyFlowJob(@RequestBody OaReturnVo oaReturnVo) {
        newOalgqsFlowService.returnZdJob(oaReturnVo);

        //退回更新通知信息
        OaJobEntity oaJobEntity = spcySqsxJobService.getById(oaReturnVo.getJobid());
        String fpid = oaJobEntity.getFpid();
        sysTzMessageService.endMessage(fpid,false,false,true);

        return HttpResult.ok("退回成功");
    }

    @AutoLog(value = "删除离岗请示流程")
    @ApiOperation(value = "删除离岗请示流程")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "jobids",value = "流程任务id,逗号分割",required = true)
    })
    @DeleteMapping(value = "deleteLgqsFlowJob")
    public HttpResult<?> deleteLgqsFlowJob(@RequestParam(value = "jobids") String jobids){
        if (StringUtils.isBlank(jobids)){
            return HttpResult.error("参数不能为空");
        }
        List<String> jobIdList = Arrays.asList(jobids.split(","));
        String logNr = "";
        Map<String, Object> map = new HashMap<>();
        if (CollectionUtils.isNotEmpty(jobIdList)){
            List<OaJobEntity> jobList = spcySqsxJobService.listByIds(jobIdList);
            if (CollectionUtils.isNotEmpty(jobList)){
                for (OaJobEntity job : jobList) {
                    spcySqsxJobService.removeById(job.getId());
                    OaLgqs oaLgqs = oaLgqsService.getById(job.getFpid());
                    if (oaLgqs != null) {
                        oaLgqsService.removeById(job.getFpid());

                        logNr = "删除离岗请示" + job.getFhjmc() + ": ";
                        map = ObjectToMapUtils.objectToMap(oaLgqs);
                        logNr += LogUtils.MapToStringMethod(map);

                        spcyLogService.addLogs(job.getFhjmc(), logNr, job.getFpid(), OaLogConstant.LOGS_OA_LGQS, OaCommonFlowConstant.LOGS_SYS_TYPE_SC);
                    }
                }
            }
        }

        return HttpResult.ok("删除成功");
    }

    /**
     * 创建业务主表内容
     *
     * @param
     * @return
     */
    @AutoLog(value = "创建业务主表内容")
    @ApiOperation(value = "创建业务主表内容")
    @GetMapping(value = "createJob")
    public HttpResult<?> createJob(String oaid){
        CurrentUserVo currentUser = ThreadContextHelper.getCurrentUser();
        String lcmbCode = OaFlowConstant.OA_LGQS;
        OaLgqs lgqsServiceById = oaLgqsService.getById(oaid);
        //初始化的时候 向 流程业务主表添加拼接初始化数据
        String bt = currentUser.getName()+"提交的离岗请示"; //标题
        String zy = "开始时间:["+DateConversionUtils.DateToYMDHMSChineseString(lgqsServiceById.getFlgsj())+"]"+"\n"
                +"结束时间:["+ DateConversionUtils.DateToYMDHMSChineseString(lgqsServiceById.getFhgsj()) + "]"+"\n"
                + "时长:"+ lgqsServiceById.getFlksj();
        oaProcessBusinessService.addProcess(oaid,zy,bt,lcmbCode,OaFlowConstant.OA);
        return HttpResult.ok("插入成功");

    }

    @AutoLog(value = "实际离岗时长列表")
    @ApiOperation(value = "实际离岗时长列表")
    @GetMapping("sjlgPage")
    public HttpResult sjlgPage(@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                               @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize){
        LambdaQueryWrapper<OaLgqs> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(OaLgqs :: getFlczt, OaCommonFlowConstant.FLOW_LCJS);
        Page<OaLgqs> page = new Page<>(pageNo, pageSize);
        Page<OaLgqs> page1 = oaLgqsService.page(page, queryWrapper);
        return  HttpResult.ok(page1);
    }




}
